<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/1/4
 * Time: 23:24
 */

namespace Home\Controller;
use Think\Controller;

class QxController extends Controller{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
        $flag = session('?dataInfo');
        if(!$flag){
            $this->error("非法登录",U('Home/Index/index'));
        }

    }

    public function qx(){
        $ret=D("Qx");
        $qxinfo = $ret->getList();
        $this->assign("qxinfo",$qxinfo)->assign("title","假期去向登记");
        $this->display();
    }

    public function addqx(){
        $qx=M('qx');
        $dataList=array(
            "name"=>session("dataInfo.name"),
            "address"=>I("post.address"),
            "contacts"=>I("post.contacts"),
            "tel"=>I("post.tel"),
            "ltime"=>I("post.ltime"),
            "btime"=>I("post.btime")
        );

        if($ret=$qx->add($dataList)){
//            $this->success('提交成功！');
            $this->redirect('Qx/qx');
        }else{
            $this->error("提交失败");
        }
    }

    public function delqx(){

        $id=I("get.id");
        $qx=D("qx");
        if($qx->del($id)){
//            $this->success('删除成功！');
            echo "<script type='text/javascript'>
                    alert('删除成功！');
                    location.href='qx';
                   </script>";
        }else{
            $this->error("删除失败");
        }
    }

    public  function updateqx(){
        $id=I("get.id");
        S('id',$id);
        $qx=D("qx");
        $ret=$qx->getItem($id);
        $this->assign("upret",$ret);
        $this->display();

        if(I('post.')){
            $data=I('post.');
            $ret=M('qx')->where("id={$id}")->save($data);
            if(false !== $ret || 0 !== $ret){
                echo "<script type='text/javascript'>
                    alert('修改成功！');
                    location.href='qx';
                   </script>";
            }else {
                $this->error('修改失败');
            }
        }
    }

//    public function upqx(){
//        $id=S('id');
//        $data=I('post.');
//        $ret=M('qx')->where("id={$id}")->save($data);
//        if(false !== $ret || 0 !== $ret){
//            S('id',null);
//            echo "<script type='text/javascript'>
//                    alert('修改成功！');
//                    location.href='qx';
//                   </script>";
//        }else {
//            $this->error('修改失败');
//        }
//    }
}